/**  
* @Description: TODO
* @author hc
* @date 2017年1月12日 下午1:55:43 
* @version V1.0   
*/
package com.demo;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;

import com.utils.HttpHelper;
import com.utils.HttpResponse;

/**
 * @author Administrator
 *
 */
public class Notify {
	public static void main(String[] args) {

	String urlString = "http://localhost:8080/ppayGate/wxPayResult.html";
	String reqStr = "<xml>"+
			"<attach>"+
			"<![CDATA[CZBH_2017011600000352]]>"+
			"</attach>"+
			"<buyer_logon_id>"+
			"<![CDATA[180****0314]]>"+
			"</buyer_logon_id>"+
			"<buyer_user_id>"+
			"<![CDATA[2088802744911024]]>"+
			"</buyer_user_id>"+
			"<charset>"+
			"<![CDATA[UTF-8]]>"+
			"</charset>"+
			"<fee_type>"+
			"<![CDATA[CNY]]>"+
			"</fee_type>"+
			"<fund_bill_list>"+
			"<![CDATA[[{\"amount\":\"1590.00\",\"fundChannel\":\"ALIPAYACCOUNT\"}]]]>"+
			"</fund_bill_list>"+
			"<mch_id>"+
			"<![CDATA[101550002245]]>"+
			"</mch_id>"+
			"<nonce_str>"+
			"<![CDATA[1484557637990]]>"+
			"</nonce_str>"+
			"<openid>"+
			"<![CDATA[2088802744911024]]>"+
			"</openid>"+
			"<out_trade_no>"+
			"<![CDATA[2017011617201901]]>"+
			"</out_trade_no>"+
			"<out_transaction_id>"+
			"<![CDATA[2017011621001004020288946828]]>"+
			"</out_transaction_id>"+
			"<pay_result>"+
			"<![CDATA[0]]>"+
			"</pay_result>"+
			"<result_code>"+
			"<![CDATA[0]]>"+
			"</result_code>"+
			"<sign>"+
			"<![CDATA[B0D115E468EBAD4D8E272C7711BA1E60]]>"+
			"</sign>"+
			"<sign_type>"+
			"<![CDATA[MD5]]>"+
			"</sign_type>"+
			"<status>"+
			"<![CDATA[0]]>"+
			"</status>"+
			"<time_end>"+
			"<![CDATA[20170116170717]]>"+
			"</time_end>"+
			"<total_fee>"+
			"<![CDATA[159000]]>"+
			"</total_fee>"+
			"<trade_type>"+
			"<![CDATA[pay.alipay.native]]>"+
			"</trade_type>"+
			"<transaction_id>"+
			"<![CDATA[101550002245201701166319062339]]>"+
			"</transaction_id>"+
			"<version>"+
			"<![CDATA[2.0]]>"+
			"</version>"+
			"</xml>";
				
//				try {
//					HttpResponse resp = HttpHelper.doHttp(urlString, "POST",
//							"UTF-8", reqStr, "600000");
////					resp.getBody()
//				System.out.println(resp);
//				} catch (Exception e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
	
		System.out.println(post(urlString, reqStr, 6000));
			
		

	}
	
	
	public  static String post(String urlStr, String xmlInfo,int timeOut) {
		try {
			URL url = new URL(urlStr);
			URLConnection con = url.openConnection();
			con.setDoOutput(true);  
			con.setDoInput(true); 
			con.setRequestProperty("Pragma:", "no-cache");
			con.setRequestProperty("Cache-Control", "no-cache");
			con.setRequestProperty("connection", "Keep-Alive");
			con.setRequestProperty("Content-Type", "text/xml");
			con.setConnectTimeout(timeOut);
			OutputStreamWriter out = new OutputStreamWriter(
					con.getOutputStream());
			System.out.println("urlStr=" + urlStr);
			System.out.println("请求xmlInfo=" + xmlInfo);
			out.write(new String(xmlInfo.getBytes("UTF-8")));
			out.flush();
			out.close();
			BufferedReader br = new BufferedReader(new InputStreamReader(
					con.getInputStream()));
			String line = "";
			String result = "";
			while ((line = br.readLine()) != null) {
				result += line;
			}
			return result;
		} catch (Exception e) {
			e.printStackTrace();
			return "出现异常";
		}
	}
}
